package com.chatroom.repository;

import com.chatroom.model.PrivateChatRoom;
import com.chatroom.model.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface PrivateChatRoomRepository extends JpaRepository<PrivateChatRoom, Long> {
    
    Optional<PrivateChatRoom> findByRoomCode(String roomCode);
    
    @Query("SELECT pcr FROM PrivateChatRoom pcr WHERE (pcr.user1 = ?1 AND pcr.user2 = ?2) OR (pcr.user1 = ?2 AND pcr.user2 = ?1)")
    Optional<PrivateChatRoom> findByUsers(User user1, User user2);
    
} 